package org.numb.concurrency.chapter02;

import java.lang.Thread.UncaughtExceptionHandler;

public class ExceptionThread extends Thread {

    @Override
    public void run() {
        int a = 1/0;
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new ExceptionThread();
        ExceptionHandler handler = new ExceptionHandler();
        thread.setUncaughtExceptionHandler(handler);
        thread.start();
    }
}

class ExceptionHandler implements UncaughtExceptionHandler {

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        System.out.println("处理异常：" + e.toString());
    }
}
